<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Cron extends CI_Controller {

    /**
     * 自动发送邮件脚本
     */
    function emailsend() {
        $protocolMailKey = "protocolMailKey";
        $mailList = $this->mycache->get_array($protocolMailKey);
        if (count($mailList) > 0) {
            //echo count($mailList);
            foreach ($mailList as $key => $tmpArr) {
                $this->load->model('User_model');
                $user_id = $tmpArr['user_id'];
                $borrow_id = $tmpArr['borrow_id'];
                $title = $tmpArr['borrow_title'];
                $tender_id = $tmpArr['tender_id'];

                //$this->load->model('User_vip_model', 'vip');
                //$this->vip->check_vip($user_id);

                $this->load->library('func');
                $html = $this->func->protocol_msg($borrow_id, $tender_id);
                $this->load->library('phpmailer/PHPMailer');
                $this->phpmailer->IsSMTP();
                $user_info = $this->User_model->get_by_uid($user_id);

                $this->phpmailer->AddAddress($user_info['email'], $user_info['username']); //收件人
                $this->phpmailer->Subject = "借款标“{$title}”的借款协议书（可到网站下载PDF格式）";
                $this->phpmailer->Body = $html;
                $res = $this->phpmailer->Send();
                if ($res) {
                    //echo "yes";
                } else {
                    //echo "no";
                }
                unset($mailList[$key]);
                $this->mycache->set_array($protocolMailKey, $mailList);
                exit;
            }
        } else {
            //echo "nobody";
        }
        //echo count($mailList);
    }

    function yjbemailsend() {
        $yjbProtocolMailKey = "yjbProtocolMailKey";
        $mailList = $this->mycache->get_array($yjbProtocolMailKey);
        if (count($mailList) > 0) {
            foreach ($mailList as $key => $tmpArr) {
                $this->load->model('User_model');
                $user_id = $tmpArr['user_id'];
                $borrow_id = $tmpArr['borrow_id'];
                $tender_id = $tmpArr['tender_id'];

                $this->load->library('func');
                $html = $this->func->yjb_pro_msg($borrow_id, $tender_id, $user_id);
                $this->load->library('phpmailer/PHPMailer');
                $this->phpmailer->IsSMTP();
                $user_info = $this->User_model->get_by_uid($user_id);

                $this->phpmailer->AddAddress($user_info['email'], $user_info['username']); //收件人
                $this->phpmailer->Subject = "易居宝（赎楼贷）协议（可到网站下载PDF格式）";
                $this->phpmailer->Body = $html;
                $res = $this->phpmailer->Send();
                unset($mailList[$key]);
                $this->mycache->set_array($yjbProtocolMailKey, $mailList);
                exit;
            }
        }
    }

    function regmoney() {
        //$today = strtotime(date('Y-m-d'));
        //$start = $today-(3600*24*5);
        //$end = $start + 3600*24;
        $time = time() - (3600 * 24 * 5);
        $this->load->model('Mydb_model');
        $sql = "UPDATE ych_account SET total=total-100,reg_money=reg_money-100 WHERE reg_money=100 AND user_id IN (SELECT user_id FROM ych_user WHERE add_time<$time)";
        $this->Mydb_model->query_sql($sql, 'set');
    }

    function expmoney() {
        //57
        $this->load->model('Mydb_model', 'mydb');
        $sql = "select * from ych_account where exp_money_12>0 or exp_money_24>0";
        $list = $this->mydb->query_sql($sql, 'list');
        foreach ($list as $val) {
            //echo $val['user_id'],'----',$val['exp_money_12'],'----',$val['exp_money_24'],"<br>";
            $mode = $val['user_id'] % 100;
            $sql = "select * from ych_account_log_{$mode} where ftype=57 order by id desc limit 1";
            $explog = $this->mydb->query_sql($sql, 'row');
            $endtime = time() - 3600 * 24 * 5; //5天有效期
            if ($explog['add_time'] < $endtime) {//到期
                $sql = "select p1.id from ych_borrow_tender as p1 left join ych_borrow as p2 on p1.borrow_id=p2.id
					where p1.add_time>{$explog['add_time']} and p2.time_limit>=12 limit 1";
                $tmpRow = $this->mydb->query_sql($sql, 'row');
                if (!$tmpRow) {
                    //扣除
                    $sql = "select * from ych_account where user_id={$val['user_id']}";
                    $account_result = $this->mydb->query_sql($sql, 'row');
                    $deduct = $account_result['exp_money_12'] + $account_result['exp_money_24'];
                    $log['user_id'] = $val['user_id'];
                    $log['ftype'] = EXP_MONEY_DEDUCT;
                    $log['money'] = $deduct;
                    $log['total'] = $account_result['total'] - $log['money'];
                    $log['use_money'] = $account_result['use_money'] - $log['money'];
                    $log['no_use_money'] = $account_result['no_use_money'];
                    $log['collection'] = $account_result['collection'];
                    $log['to_user'] = 1;
                    $log['remark'] = "体验金过期扣除";
                    $log['add_time'] = time();
                    $log['addip'] = '127.0.0.1';
                    $this->mydb->add('ych_account_log_' . $mode, $log);
                    $sql = "update ych_account set total=total-{$log['money']},use_money=use_money-{$log['money']},exp_money_12=0,exp_money_24=0 where user_id={$val['user_id']}";
                    $this->mydb->query_sql($sql, 'set');
                }
            }
        }
        echo "over";
    }

    /**
     * 自动发标系统
     */
    function borrowautopublish() {
        $this->load->model('Borrow_model');
        $data_post['where']['fstatus'] = 0;
        $data_post['where']['auto_verify_time'] = strtotime(date('Y-m-d H:i', time()));
        $data_post['where']['is_check'] = 1;
        $data_post['page_size'] = 10;
        $data_post['page_start'] = 0;
        $data_post['select'] = 1;

        $vdata = $this->Borrow_model->get_borrow_user_list($data_post);
        $borrow_list = $vdata['borrow_list'];

        if ($borrow_list) {
            foreach ($borrow_list as $v) {

                $borrow = $this->Borrow_model->get_borrow_obj($v['id']);

                if ($borrow['fstatus'] != 0) {
                    echo "该标不处于待审核状态";
                    return;
                }

                if ($borrow['ftype'] == 4) {
                    $data["lz_endtime"] = time() + 7 * 24 * 60 * 60;
                }

                $data["fstatus"] = 1;
                $data["verify_remark"] = '审核成功';
                $data["verify_time"] = $data_post['where']['auto_verify_time'];

                $data["verify_user"] = 1;
                $flag = $this->Borrow_model->verify($v['id'], $data);

                if ($flag == 1 && $data["fstatus"] == 1) {//自动投标
                    if ($borrow['ftype'] != 5 && $borrow['is_dxb'] != 1 && $borrow['is_day'] != 1) {//自动投标
                        $this->Borrow_model->auto_tender_borrow($v['id']);
                    }
                }
                $index_borrow_list_key = 'ych_index_borrow_list';
                $this->mycache->delete($index_borrow_list_key);
                $this->load->model('log_model');
                $this->log_model->add_log('[自动审核][发标]');
                echo $flag;
            }
        }
        echo "borrow_auto_publish over";
    }

    /**
     * yjb自动发标系统
     */
    function borrowyjbautopublish() {
        $data_post['where']['fstatus'] = 1;
        $data_post['where']['auto_verify_time'] = strtotime(date('Y-m-d H:i', time()));
        $data_post['where']['is_check'] = 1;

        $this->load->model('Yjb_model');
        $vdata = $this->Yjb_model->get_list($data_post);

        $borrow_list = $vdata['list'];
        if ($borrow_list) {
            foreach ($borrow_list as $v) {
                $id = intval($v['id']);
                $setArr = array(
                    'fstatus' => 2,
                    'verify_user' => 1,
                    'verify_time' => $data_post['where']['auto_verify_time'],
                    'verify_remark' => '审核通过'
                );
                $where = array('id' => $id);
                $res = $this->Yjb_model->update($setArr, $where);
                if ($res) {
                    //自动投标
                    $this->Yjb_model->yjb_auto_tender($id);
                }
                $index_yjb_key = 'ych_index_yjb';
                $this->mycache->delete($index_yjb_key);

                $this->load->model('log_model');
                $this->log_model->add_log('[易居宝自动审核][发标]');
                echo $res;
            }
        }
        echo "borrow_auto_publish over";
    }

    function adlogtxt() {
        $this->load->model('log_model');

        $m = array(3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31);
        set_time_limit(0);
        foreach ($m as $k => $val) {
            for ($i = 1; $i <= $val; $i++) {
                if ($i < 10) {
                    $i = '0' . $i;
                }
                $file = 'D:/workspace/newgsd/static/adlog/ad1_20140' . $k . $i . '.txt';
                if (file_exists($file)) {
                    $filelist_str = file_get_contents($file);
                    $filelist = explode("\r", $filelist_str);
                    foreach ($filelist as $v) {
                        $this->log_model->add_adlog(array('type' => 1, 'add_time' => strtotime('2014-0' . $k . '-' . $i . ' ' . $v)));
                    }
                }
            }
        }

        /* foreach ($m as $k=>$val){
          for($i = 1; $i <= $val; $i++){
          if($i<10){
          $i ='0'.$i;
          }
          $file = 'D:/workspace/newgsd/static/adlog/ad2_20140'.$k.$i.'.txt';
          if(file_exists($file)){
          $filelist_str = file_get_contents($file);
          $filelist = explode("\r", $filelist_str);
          foreach ($filelist as $v){
          $this->log_model->add_adlog(array('type'=>2,'add_time'=>strtotime('2014-0'.$k.'-'.$i.' '.$v)));
          }

          }

          }
          } */

        /* foreach ($m as $k=>$val){
          for($i = 1; $i <= $val; $i++){
          if($i<10){
          $i ='0'.$i;
          }
          $file = 'D:/workspace/newgsd/static/adlog/adreg2_20140'.$k.$i.'.txt';
          if(file_exists($file)){
          $filelist_str = file_get_contents($file);
          $filelist = explode("\r", $filelist_str);
          foreach ($filelist as $v){
          $this->log_model->add_adlog(array('type'=>3,'add_time'=>strtotime('2014-0'.$k.'-'.$i.' '.$v)));
          }

          }

          }
          }
         */


        echo "adlog over";
        die;
    }

    function adlog() {
        $this->load->model('log_model');
        $visit_key = 'adlog_visit_key';
        $visit_list = $this->mycache->get_array($visit_key);

        if ($visit_list) {
            foreach ($visit_list as $val) {
                $data = array('ip' => $val['ip'], 'add_time' => $val['add_time']);
                $this->log_model->add_adlog($data);
            }
            $this->mycache->delete($visit_key);
        }

        echo "adlog over";
    }

    function creditoremailsend() {
        $creditorMailKey = "creditorMailKey";
        $this->load->model('User_model');
        $mailList = $this->mycache->get_array($creditorMailKey);
        if (count($mailList) > 0) {
            foreach ($mailList as $key => $tmpArr) {

                $user_id = $tmpArr['user_id'];
                $creditor_id = $tmpArr['creditor_id'];
                $borrow_id = $tmpArr['borrow_id'];

                $user_info = $this->User_model->get_by_uid($user_id);

                $this->load->model('Borrow_model');
                $borrow = $this->Borrow_model->get_borrow_obj($borrow_id);

                $this->load->model('Creditor_model');
                $clog = $this->Creditor_model->get_by_log_id($creditor_id);

                $this->load->library('func');
                $html = $this->func->protocol_msg_creditor($clog['obj_id'], $user_id, $creditor_id);

                $this->load->library('phpmailer/PHPMailer');
                $this->phpmailer->IsSMTP();


                $this->phpmailer->AddAddress($user_info['email'], $user_info['username']); //收件人
                $this->phpmailer->Subject = $borrow['title'] . "债权借款协议书（可到网站下载PDF格式）";
                $this->phpmailer->Body = $html;
                $res = $this->phpmailer->Send();

                unset($mailList[$key]);
                $this->mycache->set_array($creditorMailKey, $mailList);
                exit;
            }
        }
    }

    function oldemailsend() {
        $oldprotocolMailKey = "oldprotocolMailKey";
        $mailList = $this->mycache->get_array($oldprotocolMailKey);
        if (count($mailList) > 0) {
            foreach ($mailList as $key => $tmpArr) {
                $this->load->model('User_model');
                $user_id = $tmpArr['user_id'];
                $borrow_id = $tmpArr['borrow_id'];
                $tender_id = $tmpArr['tender_id'];

                $this->load->model('Borrow_model');
                $borrow = $this->Borrow_model->get_borrow_obj($borrow_id);

                $this->load->library('func');
                $html = $this->func->protocol_msg($borrow_id, $tender_id);
                $this->load->library('phpmailer/PHPMailer');
                $this->phpmailer->IsSMTP();
                $user_info = $this->User_model->get_by_uid($user_id);

                $this->phpmailer->AddAddress($user_info['email'], $user_info['username']); //收件人
                $this->phpmailer->Subject = "原借款" . $borrow['title'] . "协议书（可到网站下载PDF格式）";
                $this->phpmailer->Body = $html;
                $res = $this->phpmailer->Send();

                unset($mailList[$key]);
                $this->mycache->set_array($oldprotocolMailKey, $mailList);
                exit;
            }
        }
    }

    /**
     * 每日回款邮件生成
     */
    function replymail() {
        $now = time();
        $mkey = "repay_send_mail";
        $mailList = array();
        $this->load->model('Mydb_model');

        $sql = "SELECT p1.user_id,p2.username,p2.email,p2.privacy
	FROM ych_user_vip AS p1
	LEFT JOIN ych_user AS p2 ON p1.user_id=p2.user_id
	WHERE p1.vip_status=1 AND p1.vip_verify_time+3600*24*365>{$now} AND p2.email_status=1 and p2.user_id=226";
        $list = $this->Mydb_model->query_sql($sql, 'list');
        foreach ($list as $val) {
            $tmp = json_decode($val['privacy'], true);
            if (isset($tmp['reply']) && $tmp['reply'] == 1) {
                $user_id = $val['user_id'];
                $start = strtotime(date('Y-m-d'));
                $end = $start + 3600 * 24;
                $sql = "SELECT
					SUM(t1.repay_account) AS money
					FROM ych_borrow_collection AS t1 LEFT JOIN ych_borrow AS t2 ON t1.borrow_id=t2.id
					WHERE t2.fstatus=3 AND t1.user_id={$user_id} AND t1.fstatus=0 AND t1.repay_time>={$start} AND t1.repay_time<{$end};";
                $row1 = $this->Mydb_model->query_sql($sql, 'row');

                $sql = "SELECT SUM(repayment_account) AS money
					FROM ych_yjb_tender
					WHERE user_id={$user_id} AND fstatus<3 AND repay_time>={$start} AND repay_time<{$end}";
                $row2 = $this->Mydb_model->query_sql($sql, 'row');

                $sql = "SELECT SUM(p1.repay_account*p4.discount_buy/p4.discount_account) AS money
					FROM ych_borrow_collection AS p1
					LEFT JOIN ych_borrow AS p2 ON p1.borrow_id=p2.id
					LEFT JOIN ych_borrow_tender AS p3 ON p1.tender_id=p3.id
					LEFT JOIN ych_creditor_log AS p4 ON p3.id=p4.tender_id
					WHERE p2.fstatus=3 AND p4.user_id={$user_id} AND p4.fstatus<4 AND p1.fstatus=0 AND p1.repay_time>={$start} AND p1.repay_time<{$end}";
                $row3 = $this->Mydb_model->query_sql($sql, 'row');

                $money1 = $row1['money'] ? $row1['money'] : 0;
                $money2 = $row2['money'] ? $row2['money'] : 0;
                $money3 = $row3['money'] ? intval($row3['money'] * 100) / 100 : 0;

                $money = $money1 + $money2 + $money3;
                if ($money > 0) {
                    $msg = '亲爱的壹投资用户 ' . $val['username'] . '，您好！您今日回款金额为：' . $money . '元，请注意查收！';
                    //$mailList = $this->mycache->get_array($mkey);
                    $mailList[] = array(
                        'user_id' => $user_id,
                        'username' => $val['username'],
                        'email' => $val['email'],
                        'msg' => $msg
                    );
                }
            }
        }
        $this->mycache->set_array($mkey, $mailList);
    }

    /**
     * 每日回款邮件发送
     */
    function replymailsend() {
        $mkey = "repay_send_mail";
        $mailList = $this->mycache->get_array($mkey);
        if (count($mailList) > 0) {
            foreach ($mailList as $key => $tmpArr) {
                $this->load->library('phpmailer/PHPMailer');
                $this->phpmailer->IsSMTP();
                $this->phpmailer->AddAddress($tmpArr['email'], $tmpArr['username']); //收件人
                $this->phpmailer->Subject = CON_PLATFORMNAME . "回款提醒";
                $this->phpmailer->Body = $tmpArr['msg'];
                $this->phpmailer->Send();
                unset($mailList[$key]);
                $this->mycache->set_array($mkey, $mailList);
                exit;
            }
        }
    }

    function invite_reward1() {
        /* $end_time = strtotime(date("Y-m-01"));
          $str_time = strtotime("-1 month", $end_time); */

        //测试，模拟时间
        $str_time = strtotime("2014-01-01");
        $end_time = strtotime("2014-12-31");

        $this->load->model('User_model');
        $this->load->model('Borrow_model');
        $dingji = $this->User_model->get_list(array('invite_userid' => 0), 'user_id,username,invite_money,add_time');
        foreach ($dingji as $dj) {
            $yiji = $this->User_model->get_list(array('invite_userid' => $dj['user_id']), 'user_id,username,invite_money,add_time');
            foreach ($yiji as $yj) {
                $tmoney = $this->Borrow_model->get_user_tender_money($yj['user_id'], $str_time, $end_time);
                if ($tmoney > 0) {
                    $realmoney = $tmoney * INVITE_ONE / 100;
                    $this->User_model->set_invite_money($dj['user_id'], $realmoney);
                    self::backcharge($dj['user_id'], $realmoney, "一级推荐奖励");
                }
                $erji = $this->User_model->get_list(array('invite_userid' => $yj['user_id']), 'user_id,username,invite_money,add_time');
                foreach ($erji as $ej) {
                    $tmoney = $this->Borrow_model->get_user_tender_money($ej['user_id'], $str_time, $end_time);
                    if ($tmoney > 0) {
                        $realmoney = $tmoney * INVITE_ONE / 100;
                        $this->User_model->set_invite_money($yj['user_id'], $realmoney);
                        self::backcharge($yj['user_id'], $realmoney, "一级推荐奖励");


                        $realmoney = $tmoney * INVITE_TWO / 100;
                        $this->User_model->set_invite_money($dj['user_id'], $realmoney);
                        self::backcharge($dj['user_id'], $realmoney, "二级推荐奖励");
                    }
                }
            }
        }
        echo "over";
    }

    function invite_reward() {
        /* $end_time = strtotime(date("Y-m-01"));
          $str_time = strtotime("-1 month", $end_time); */
        set_time_limit(0);
        //测试，模拟时间
        $str_time = strtotime(date('Y-m-1', strtotime('last month')));  //大于等于上个月的月初
        $end_time = strtotime(date('Y-m-1')); //小于这个月的月初
        $monthFirstDay = strtotime(date('Y-m-1'));

        $this->load->model('User_model');
        $this->load->model('Borrow_model');
        $this->load->model('Account_model');
        $dingji = $this->User_model->get_list(array(), 'user_id,username,invite_money,add_time, inviteTime');
        foreach ($dingji as $dj) {
            var_dump($dj['user_id']);
            //这个月发过了，不再发
            if ($dj['inviteTime'] > $monthFirstDay ){
                continue;
            }
            $account = $this->Account_model->get_account($dj['user_id']);
            $this->User_model->update(array('inviteTime'=>time()),array('user_id'=>$dj['user_id']));
            $yiji = $this->User_model->get_list(array('invite_userid' => $dj['user_id']), 'user_id,username,invite_money,add_time');
            foreach ($yiji as $yj) {
                var_dump(' yj:'.$yj['user_id']);
                $tmoney = $this->Borrow_model->get_user_tender_interest($yj['user_id'], $str_time, $end_time);
                var_dump(' tmoney:'.$tmoney);
                if ($tmoney > 0) {
                    $realmoney = $tmoney * INVITE_ONE;
                    //用户表添加奖励金额,修改invite_money
                    $this->db->query("update ych_user set invite_money=invite_money+{$realmoney} where user_id={$dj['user_id']}");
                    //资金表增加对应金额,修改total,use_money
                    $this->Account_model->add_invite_money($account['id'],$realmoney);
                    //添加记录到投资流水表
                    $data = array(
                        'user_id' => $yj['user_id'],
                        'yiji_referee' => $dj['user_id'],
                        'yiji_reward_money' => $realmoney,
                    );
                    $this->Borrow_model->insert_invite_list($data);
                }
                $erji = $this->User_model->get_list(array('invite_userid' => $yj['user_id']), 'user_id,username,invite_money,add_time');
                foreach ($erji as $ej) {
                    var_dump('  ej:'.$ej['user_id']);
                    $tmoney = $this->Borrow_model->get_user_tender_interest($ej['user_id'], $str_time, $end_time);
                    var_dump('  tmoney:'.$tmoney);
                    if ($tmoney > 0) {
                        $realmoney = $tmoney * INVITE_TWO;
                        //用户表添加奖励金额,修改invite_money
                        $this->db->query("update ych_user set invite_money=invite_money+{$realmoney} where user_id={$dj['user_id']}");
                        //资金表增加对应金额,修改total,use_money
                        $this->Account_model->add_invite_money($account['id'],$realmoney);
                        //添加记录到投资流水表
                        $data = array(
                            'user_id' => $ej['user_id'],
                            'dingji_referee' => $dj['user_id'],
                            'dingji_reward_money' => $realmoney,
                        );
                        $this->Borrow_model->insert_invite_list($data);
                    }
                }
            }
        }
        echo "over";
    }

    public function backcharge($uid, $money, $info) {
        $this->load->library('/mmm/Rsa', 'rsa');
        $this->load->library('/mmm/Common', 'common');
        $this->load->library('/mmm/LoanInfoBean', 'loaninfobean');
        $this->load->library('/mmm/LoanInfoSecondaryBean', 'loaninfosecondarybean');

        $this->load->model("User_model");
        $user = $this->User_model->get_by_uid($uid);
        if ($user['mmm_id'] == "") {
            return;
        }
        $PlatformMoneymoremore = MONEYMOREMOREPID;

        $ExchangeBatchNo = "";
        $AdvanceBatchNo = "";
        $loaninfo1 = new LoanInfoBean($PlatformMoneymoremore, $user['mmm_id'], date("YmdHis"), date("YmdHis"), $ExchangeBatchNo, $AdvanceBatchNo, $money, $money, "平台充值", $info, "");
        $arrloaninfo = array('0' => array("LoanOutMoneymoremore" => $loaninfo1->LoanOutMoneymoremore,
                "LoanInMoneymoremore" => $loaninfo1->LoanInMoneymoremore,
                "OrderNo" => $loaninfo1->OrderNo,
                "BatchNo" => $loaninfo1->BatchNo,
                "ExchangeBatchNo" => $loaninfo1->ExchangeBatchNo,
                "AdvanceBatchNo" => $loaninfo1->AdvanceBatchNo,
                "Amount" => $loaninfo1->Amount,
                "FullAmount" => $loaninfo1->FullAmount,
                "TransferName" => $loaninfo1->TransferName,
                "Remark" => $loaninfo1->Remark,
                "SecondaryJsonList" => $loaninfo1->SecondaryJsonList));
        $LoanJsonList = json_encode($arrloaninfo);

        $TransferAction = "3";
        $Action = "2";
        $TransferType = "2";
        $NeedAudit = "1";
        $common = new Common();
        if ($common->getAntiState() == 0) {
            $RandomTimeStamp = "";
        } else if ($common->getAntiState() == 1) {
            $RandomTimeStamp = $common->getRandomTimeStamp();
        }
        $Remark1 = $uid;
        $Remark2 = $info;
        $Remark3 = "";
        $ReturnURL = "";
        $NotifyURL = "http://" . $_SERVER["HTTP_HOST"] . "/moneymoremore/transfernotify.html";

        $dataStr = $LoanJsonList . $PlatformMoneymoremore . $TransferAction . $Action . $TransferType . $NeedAudit . $RandomTimeStamp . $Remark1 . $Remark2 . $Remark3 . $ReturnURL . $NotifyURL;
        if ($common->getAntiState() == 1) {
            $dataStr = strtoupper(md5($dataStr));
        }
        $rsa = new RSA();
        $SignInfo = $rsa->sign($dataStr);

        $LoanJsonList = urlencode($LoanJsonList);

        $post_data = array();
        $post_data['LoanJsonList'] = $LoanJsonList;
        $post_data['PlatformMoneymoremore'] = $PlatformMoneymoremore;
        $post_data['TransferAction'] = $TransferAction;
        $post_data['Action'] = $Action;
        $post_data['TransferType'] = $TransferType;
        $post_data['NeedAudit'] = $NeedAudit;
        $post_data['RandomTimeStamp'] = $RandomTimeStamp;
        $post_data['Remark1'] = $Remark1;
        $post_data['Remark2'] = $Remark2;
        $post_data['Remark3'] = $Remark3;
        $post_data['ReturnURL'] = $ReturnURL;
        $post_data['NotifyURL'] = $NotifyURL;
        $post_data['SignInfo'] = $SignInfo;

        $moreMorePlat = MONEYMOREMOREPID;
        $urlMoneymoremore = MONEYMOREMOREURL;
        $url = $urlMoneymoremore . '/loan.action';
        $o = "";
        foreach ($post_data as $k => $v) {
            $o.= "$k=" . urlencode($v) . "&";
        }
        $post_data = substr($o, 0, -1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //为了支持cookie
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $result = curl_exec($ch);
        $fp = fopen("d:/ch/bangka.txt", "a"); //文件被清空后再写入
        $flag = fwrite($fp, $result);
        fclose($fp);
        $jdate = substr($result, 1, strlen($result) - 2);
        $jdataarray = explode('},{', $jdate);
        $index = 0;
        $account_list = array();
        foreach ($jdataarray as $ja) {
            if ($index == 0) {
                $account_list[] = json_decode($ja . "}", true);
            } else {
                $account_list[] = json_decode("{" . $ja, true);
            }
            $index++;
        }
        $done = false;

        if ($account_list[1]['ResultCode'] == 88) {
            $this->load->model("Account_model");
            $account_obj = $this->Account_model->get_account($uid);
            $log = array(
                'user_id' => $uid,
                'ftype' => INVITE_REWARD, //提现失败
                'money' => $money,
                'total' => $account_obj['total'] + $money,
                'use_money' => $account_obj['use_money'] + $money,
                'no_use_money' => $account_obj['no_use_money'],
                'collection' => $account_obj['collection'],
                'to_user' => 1,
                'remark' => $info,
                'add_time' => time(),
                'addip' => "127.0.0.1",
            );
            $this->Account_model->accountlog($log);
        }
        return $done;
    }

}
